package PTA_JAVA.JavaB.Javademo13;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        ArrayList<Person> arr = new ArrayList<Person>();
        for (int i = 0; i < 3; i++) {
            String[] s= sc.nextLine().split(" ");
            Address add = new Address(s[2],s[3],s[4],s[5],s[6]);
            Person p=new Person(s[0],s[1],add);
            arr.add(p);
        }
        System.out.println("add success!");
        int id = Integer.parseInt(sc.next());
        for(Person i:arr){
            if(id==i.getId()){
                arr.remove(i);
                break;
            }
        }
        System.out.println("delete success!");
        id = Integer.parseInt(sc.next());
        sc.nextLine();
        String[] s= sc.nextLine().split(" ");
        for(Person i:arr){
            if(id==i.getId()){
                i.setName(s[0]);
                i.setPhoneNumber(s[1]);
                Address add = new Address(s[2],s[3],s[4],s[5],s[6]);
                i.setAddress(add);
                System.out.println("change success!");
                break;
            }
        }

        id = Integer.parseInt(sc.next());
        int f=0;
        for(Person i:arr){
            if(id==i.getId()){
                f=1;
                System.out.println(i.toString());
                System.out.println("find success!");
                break;
            }
        }
        if(f==0){
            System.out.println("Not found!");
        }

        for(Person i:arr){
            System.out.println(i.toString());
        }
    }
}
class Person{
    private static String hostname;
    private int id;
    private String name;
    private String phoneNumber;
    private Address address;
    static int count=0;//记录最新的id值。
    //初始化块:
    /* 初始化块主要用于对象的初始化操作，
     * 在创建对象时调用，可以用于完成初始化属性值、加载其他类等功能。
     * 初始化块的执行顺序在构造方法之前，
     * 如果构造方法多次重载，此时可以考虑将构造方法中共通的代码提到初始化块中定义。
     *静态初始化块：
     * 静态初始化块主要用于初始化静态变量和静态方法。
     * 静态初始化块只调用一次，是在类被第一次加载到内存时，并非要创建对象才执行。
     */
    {
        id=++count;
    }
    static{
        hostname="zhangsan";
        System.out.println("init");
        System.out.println("zhangsan");
    }
    Person(String name, String phoneNumber, Address address){
        this.name=name;
        this.phoneNumber=phoneNumber;
        this.address=address;
    }

    public static String getHostname() {
        return hostname;
    }

    public static void setHostname(String hostname) {
        Person.hostname = hostname;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @Override
    public String toString() {
        return "Person [" +
                "id=" + id +
                ", name=" + name +
                ", phoneNumber=" + phoneNumber +
                ", address=" + address +
                ']';
    }
}
class Address{
    private String country;
    private String province;
    private String city;
    private String street;
    private String zipcode;

    Address(String country, String province, String city, String street, String zipcode){
        this.country=country;
        this.province = province;
        this.city = city;
        this.street = street;
        this.zipcode = zipcode;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getZipcode() {
        return zipcode;
    }

    public void setZipcode(String zipcode) {
        this.zipcode = zipcode;
    }

    @Override
    public String toString() {
        return "Address [" +
                "country=" + country +
                ", province=" + province +
                ", city=" + city  +
                ", street=" + street  +
                ", zipcode=" + zipcode +
                ']';
    }
}
